package thinkingJava.chapter16;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

class CompTypeComparator implements Comparator<CompType> {

	public int compare(CompType o1, CompType o2) {
		return o1.j < o2.j ? -1 : (o1.j == o2.j ? 0 : 1);
	}

}

public class ComparatorTest {

	public static void main(String[] args) {
		CompType[] a = new CompType[12];
		for (int i = 0; i < a.length; i++) {
			a[i] = CompType.generator().next();
		}
		System.out.println("before sorted: ");
		System.out.println(Arrays.toString(a));
		Arrays.sort(a, new CompTypeComparator());//Comparable
		System.out.println("after sorted: ");
		System.out.println(Arrays.toString(a));
	}
	public static void print(Object o) {
		System.out.println(o);
	}

}
